<?php
defined('CR_BASE') or exit('hacking attempt');

class Db extends Object{
    public $memKey='';

    public function insert($data,$options){
        $sql="INSERT INTO {$options['table']}(".implode(',', array_keys($data)).') VALUES ('.implode(',', array_fill(0, count($data), '?')).');';
        $values=array_values($data);
        $this->memKey=$this->oriSql($sql,$values);
        $this->query($sql,$values);
        return $this->getLastInsertId();
    }

    
    /*
     * 完整的sql语句,方便调试
     * */
    private function oriSql($sql,$values){
        array_walk($values, 'addslashes');
        if (strpos($sql, '%s')!==false)return false;
        $sql=str_replace('?', '%s', $sql);
        array_unshift($values, $sql);
        return call_user_func_array('sprintf', $values);
    }
    
    public function update(){
        exit('update');
    }


    
}